<template>
  <div>
    <el-button type="text" @click="dialogVisible = true">新增</el-button>
    <el-card>
      <el-table
        :data="tableData"
        border
        style="width: 100%">
        <el-table-column
          prop="platformId"
          label="id"
          width="180">
        </el-table-column>
        <el-table-column
          prop="platformName"
          label="客服名"
          width="180">
        </el-table-column>
        <el-table-column
          prop="platformImage"
          label="图片">
          <template slot-scope="scope">
            <el-image :src="scope.row.platformImage"></el-image>
          </template>
        </el-table-column>
        <el-table-column
          prop="platformPhone"
          label="手机号">
        </el-table-column>
        <el-table-column
          prop="platformEmail"
          label="邮箱">
        </el-table-column>
        <el-table-column
          prop="sex"
          label="性别">
          <template slot-scope="scope">
            <span v-if="scope.row.sex==1">男</span>
            <span v-if="scope.row.sex==2">女</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="age"
          label="性别">
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
            <el-button @click="customerDelete(scope.row.platformId)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="提示"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
        <el-form :model="platform" status-icon  ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-form-item label="请输入用户名" >
            <el-input  v-model="platform.platformName"></el-input>
          </el-form-item>
          <el-form-item label="请输入手机号" >
            <el-input  v-model="platform.platformPhone"></el-input>
          </el-form-item>
          <el-form-item label="请选择性别" >
            <el-radio-group v-model="platform.sex" size="medium">
              <el-radio border label="1">男</el-radio>
              <el-radio border label="2">女</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="请选择邮箱号" >
            <el-input v-model="platform.platformEmail"></el-input>
          </el-form-item>
          <el-form-item label="请选择年龄" >
            <el-input v-model.number="platform.age"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="customerInsert()">提交</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
  import { customerSelect, customerInsert, customerDelete ,customerUpddate } from '@/api/users'
  export default {
    name: 'Index',
    data(){
      return {
        platform:{
          platformName:'',
          platformPassword:'123456',
          platformPhone:'',
          platformEmail:'',
          sex:'',
          age:'',
          role:3
        },
        dialogVisible: false,
        tableData: []
      }
    },
    mounted(){
    this.customerSelect()
    },
    methods:{
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      customerDelete(row){
        customerDelete(row).then((res)=>{
          this.customerSelect()
        })
      },
      customerSelect(){
        customerSelect().then((res)=>{
          console.log(res.data)
          this.tableData=res.data
        })
      },
      customerInsert(){
        console.log(this.platform)
        this.dialogVisible = false
        customerInsert(this.platform).then((res)=>{
          this.customerSelect()
          this.platform=[]
        })
      }
    }
  }
</script>

<style scoped></style>
